//
//  ZWPropertyCell.m
//  NewProject
//
//  Created by tongtong on 2018/5/18.
//  Copyright © 2018年 chenIos. All rights reserved.
//

#import "ZWPropertyCell.h"
@interface ZWPropertyCell ()

@property (nonatomic,strong) UILabel *contentLabel;//标题
@property (nonatomic,strong) UILabel *moneyLabel;//数目
@property (nonatomic,strong) UILabel *switchLabel;//转换数目
@property (nonatomic,strong) UIView *lineView;//分割线

@end

@implementation ZWPropertyCell
#pragma mark - init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview];
    }
    return self;
}
- (void)setCurrencyUnit:(NSString *)currencyUnit pais:(NSString *)pais currency:(NSString *)currency money:(NSNumber *)money
{
    double moneySign = pais.doubleValue;
    self.moneyLabel.text = [NSString stringWithFormat:@"%.8lf",moneySign];
    self.contentLabel.text = currency;
    moneySign = [money doubleValue];
    if ([currencyUnit isEqualToString:@"CNY"]) {
         _switchLabel.text = [@"≈￥" stringByAppendingString:[NSString stringWithFormat:@"%.2lf",moneySign]];
    }else if ([currencyUnit isEqualToString:@"USD"]){
        moneySign = moneySign/6.386;
         _switchLabel.text = [@"≈$" stringByAppendingString:[NSString stringWithFormat:@"%.2lf",moneySign]];
    }
    self.imag.image = [UIImage imageNamed:currency];

   
}

#pragma mark - add subviews
- (void)addSubview {
    [self addSubview:self.imag];
    [self addSubview:self.contentLabel];
    [self addSubview:self.moneyLabel];
    [self addSubview:self.lineView];
    [self addSubview:self.switchLabel];
    [self layoutSubviews];
}
#pragma mark - layout subviews
- (void)layoutSubviews {
    ZWWeakSelf;
    [_imag mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(@Scare_Width(24));
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.left.equalTo(@Scare_Width(20));
        make.size.mas_equalTo(CGSizeMake(Scare_Width(38), Scare_Width(38)));
    }];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(@Scare_Width(35));
        make.centerY.mas_equalTo(weakSelf.imag.mas_centerY);
        make.left.equalTo(weakSelf.imag.mas_right).offset(Scare_Width(17));
    }];
    [_moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.imag.mas_top);

        make.right.equalTo(weakSelf.mas_right).mas_offset(-Scare_Width(20));
    }];
    
    [_switchLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.moneyLabel.mas_bottom).mas_offset(Scare_Width(0));
        make.right.equalTo(weakSelf.mas_right).offset(-Scare_Width(20));
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.mas_bottom).offset(-Scare_Width(0.5));
        make.left.equalTo(weakSelf.mas_left);
        make.size.mas_equalTo(CGSizeMake(SCREEN_W, Scare_Width(0.5)));
    }];
}
#pragma mark --set---
- (UIImageView *)imag {
    if (!_imag) {
        _imag = [[UIImageView alloc] init];
        _imag.image = [UIImage imageNamed:@"pkc_coin"];
        _imag.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _imag;
}
- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = H_Medium2;
        _contentLabel.textColor = [UIColor colorWithHexString:@"#5a697c"];
        _contentLabel.text = @"WE";
    }
    return _contentLabel;
}
- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] init];
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#5a697c"];;
//        _moneyLabel.backgroundColor = [UIColor redColor];
        _moneyLabel.font = H_Medium5;
        _moneyLabel.text= @"0";
        _moneyLabel.textAlignment = NSTextAlignmentRight;
    }
    return _moneyLabel;
}
- (UILabel *)switchLabel {
    if (!_switchLabel) {
        _switchLabel = [[UILabel alloc] init];
        _switchLabel.textColor = COLOR_MIDDLE_GRAY;
        _switchLabel.font = H_Medium6;
        _switchLabel.text = @"≈￥0";
        _switchLabel.textAlignment = NSTextAlignmentRight;
    }
    return _switchLabel;
}
-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = COLOR_LIGHT_GRAY;
    }
    return _lineView;
}
@end
